package utilitario;

import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JFormattedTextField;
import javax.swing.text.MaskFormatter;

public class JTextFieldFormatoFecha extends JFormattedTextField {

	
	private static final long serialVersionUID = 1L;
    JFormattedTextField textoBorde;

    public JTextFieldFormatoFecha(MaskFormatter parMask) {

        super(parMask);
        super.setDisabledTextColor(Color.BLACK);

        textoBorde = new JFormattedTextField();
        super.addPropertyChangeListener(new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                JFormattedTextField control = (JFormattedTextField) evt.getSource();
                if (control.isEnabled()) {

                    control.setBorder(textoBorde.getBorder());
//                    control.setBackground(Color.WHITE);
                    control.setOpaque(true);

                } else if (!control.isEnabled()) {

                    control.setBorder(javax.swing.BorderFactory.createEtchedBorder());
                    control.setBackground(textoBorde.getBackground());
                    control.setOpaque(false);

                }
            }
        });

        super.addFocusListener(new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {

                JFormattedTextField control = (JFormattedTextField) e.getSource();
                control.setBackground(Color.YELLOW);
                control.setOpaque(true);

            }

            @Override
            public void focusLost(FocusEvent e) {

                JFormattedTextField control = (JFormattedTextField) e.getSource();
                control.setBackground(Color.WHITE);
                control.setOpaque(true);

            }
        });
    }//Fin de Constructor    
}